﻿(function () {

    var AppIns = function () {
        var self = this;
        function _getMeta(callback) {

            $.when(
               $.getJSON('/simpleapp/inspire/getinspire')
            ).done(function (m) {
                self.main = JSON.parse(m);
                callback(_getRandom(self.main));
            });
        }

        function _getMain() {
            return self.main;
        }


        function _getRandom(a) {
            var result = [];
            var length = a.length;
            var index1 = Math.floor(Math.random() * length);
            var index2 = Math.floor(Math.random() * length);
            var index3 = Math.floor(Math.random() * length);
            result.push(getSplit(a[index1].NAME));
            result.push(getSplit(a[index2].NAME));
            result.push(getSplit(a[index3].NAME));
            return result;
        }

        function getSplit(a) {
            var result = [];
            for (var i = 0; i < a.length; i++) {
                result.push(a[i]);
            }
            return result.join(' ');
        }

        return {
            getMeta: _getMeta
        }
    }
    if (!window.AppIns)
        window.AppIns = AppIns();
})();